﻿using HeadFirst._02.Observer.Display.Interface;
using HeadFirst._02.Observer.Observer.Interface;
using HeadFirst._02.Observer.Subjects.Implementations;
using System;
using System.Collections.Generic;
using System.Text;

namespace HeadFirst._02.Observer.Observer.Implementations
{
    public class CurrentConditionsDisplay : IObserverable, IDisplayElement
    {
        private WeatherData _weather;
        public CurrentConditionsDisplay(WeatherData weather)
        {
            _weather = weather;
            weather.RegisterObserver(this);
        }
        public void Subscribe()

        {
            _weather.RegisterObserver(this);

        }
        public void UnSubscribe()
        {
            _weather.RemoveObserver(this);

        }
        public void Display()
        {
            Console.WriteLine($"当前气温是:{Temp}摄氏度");
        }
        public double Temp { get; set; }
        public double Humidity { get; set; }
        public double Pressure { get; set; }
        public void Update(double temp, double humidity, double pressure)
        {
            Temp = temp;
            Humidity = humidity;
            Pressure = pressure;
            Display();
        }
    }
}
